package cn.hr.services.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.hr.dao.CommonDao;
import cn.hr.entity.Company;
import cn.hr.services.ICompanyService;
import cn.hr.vo.PageAttribute;


/**                                        
 * 公司服务类               
 * @author			翁志艺                
 * @version			1.0                     
 * create Date		Apr 26, 2010
 */
@Service("companyService")
public class CompanyServiceImpl implements ICompanyService {

	@Resource(name="commonDao")
	private CommonDao commonDao;
	
	public boolean add(Company company) {
		boolean flag = false;
		try{
			commonDao.save(company);
			flag = true;
		}catch(Exception e) {
			e.printStackTrace();
		}
		return flag;
	}

	public boolean del(Company company) {
		return false;
	}

	public Company getById(Long id) {
		try{
			return (Company) commonDao.get(Company.class, id);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public PageAttribute getCompanysBySizeAndPage(int size, int page) {
		int count = -1;
		List<Company> list = null;
		
		try{
			count = commonDao.count(Company.class);
			list = (List<Company>)commonDao.find(Company.class, page, size);
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		PageAttribute pageAttribute = null;
		
		if(count!=-1 && list!= null){
			pageAttribute = new PageAttribute();
			pageAttribute.setAllCount(count);
			pageAttribute.setPageList(list);
		}
		
		
		return pageAttribute;
	}

	public boolean update(Company company) {
		boolean flag = false;
		try{
			commonDao.update(company);
			flag = true;
		}catch(Exception e) {
			e.printStackTrace();
		}
		return flag;
	}

	public CommonDao getCommonDao() {
		return commonDao;
	}

	public void setCommonDao(CommonDao commonDao) {
		this.commonDao = commonDao;
	}

	
}
